<template>
    <div class="body-container">
        <div>
            <span class="paper-title">正在进行的考试</span>
        </div>
        <el-table
                v-loading="loading"
                :data="examTableData"
                border
                style="width: 100%"
                title="正在进行的考试">
            <el-table-column
                    fixed
                    prop="examName"
                    label="考试名称"
                    width="150">
            </el-table-column>
            <el-table-column
                    prop="className"
                    label="考试班级"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="examStartTime"
                    label="开始考试时间"
                    width="150">
            </el-table-column>
            <el-table-column
                    prop="examLimitTime"
                    label="考试时长(min)"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="examDescription"
                    label="考试介绍"
                    width="120">
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="150">
                <template slot-scope="scope">
                    <router-link :to="'/paper/' + scope.row.classId" >
                        <el-button type="text" size="small" style="margin-right: 10px;" >进入考试</el-button>
                    </router-link>
                    <el-button type="text" size="small">联系老师</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>

    import {request} from "../../../api/request";

    export default {
        name: "ExamNow",
        mounted() {
            this.studentInfo = this.$store.getters.getStudentInfo;
            let that = this;
            that.loading = true;

            request({
                method: 'post',
                url: '/student/exam/now/' + this.studentInfo.stuId
            }).then(function (data) {
                data = data.data;
                that.examTableData = data.data;
                for(let i = 0 ; i < that.examTableData.length; i ++ ) {
                    that.examTableData[i].examStartTime = that.getCurrentTime(that.examTableData[i].examStartTime);
                }
                setTimeout(_ => {
                    that.loading = false;
                }, 100);
            }).catch(function (err) {

            });
        },
        methods: {
            getCurrentTime(date) {
                return new Date(date).format('yyyy-MM-dd hh:mm:ss');
            }
        },
        data() {
            return {
                page: 1,
                studentInfo: {},
                examTableData: [],
                loading: true,

            }
        }
    }
</script>

<style scoped>
    .paper-title {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
        display: inline-block;
        font-size: 16px;
        font-weight: 700;
        margin-bottom: 20px;
        color: #303133;
    }
</style>